package com.woniuxy.controller;


import com.woniuxy.demo.Result;
import com.woniuxy.enums.CodeEnum;
import com.woniuxy.exception.PawnShopException;
import com.woniuxy.param.UpdateEvalutionParam;
import com.woniuxy.service.EvalutionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zcx,ftl,gr,rhs
 * @since 2022-01-06
 */
@RestController
@RequestMapping("/evalution")
public class EvalutionController {
    @Autowired
    private EvalutionService evalutionService;

    /**
     * 根据Id查估价
     *
     * @param goodId
     * @return
     */
    @GetMapping("/getEvalution/{goodId}")
    @ApiOperation("根据Id查估价")
    public Result getEvalution(@PathVariable Integer goodId) {
        if (!StringUtils.isEmpty(evalutionService.getEvalution(goodId))) {
            return Result.newInstance().setCode(200).setMsg("查询成功").setData(evalutionService.getEvalution(goodId));
        }
        throw new PawnShopException(CodeEnum.SHOP_SELECT_FAIL.getMessage(), CodeEnum.SHOP_SELECT_FAIL.getCode());
    }

    /**
     * 添加估价
     *
     * @param updateEvalutionParam
     * @return
     */
    @PostMapping("/SaveEvalution")
    @ApiOperation("添加估价")
    public Result SaveEvalution(@RequestBody UpdateEvalutionParam updateEvalutionParam) {
        if (evalutionService.updateEvalution(updateEvalutionParam)) {
            return Result.newInstance().setCode(200).setMsg("添加成功").setData(updateEvalutionParam);
        }
        throw new PawnShopException(CodeEnum.SHOP_SELECT_FAIL.getMessage(), CodeEnum.SHOP_SELECT_FAIL.getCode());
    }

}

